package com.mashibing.test.case7.base.full.config;

import com.mashibing.test.case7.base.full.condition.WindowsCondition;
import com.mashibing.test.case7.base.full.condition.LinuxCondition;
import com.mashibing.test.case7.base.full.condition.MyDeferredImportSelector;
import com.mashibing.test.case7.base.full.condition.MyImportBeanDefinitionRegistrar;
import com.mashibing.test.case7.base.full.condition.MyImportSelector;
import com.mashibing.test.case7.entities.Book;
import com.mashibing.test.case7.entities.Person;
import com.mashibing.test.case7.entities.Teacher;
import com.mashibing.test.case7.base.full.filter.MyTypeFilter;

import com.mashibing.test.case7.entities.colors.Color;
import com.mashibing.test.case7.entities.colors.Red;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Controller;
import com.mashibing.test.case7.scan.pkg1.BookService;

@Conditional({WindowsCondition.class})
@Configuration
@PropertySource(value = {"classpath:com/mashibing/test/case7/base/test.properties"},encoding="UTF-8")
@ComponentScan(basePackages = "com.mashibing.test.case7.scan.pkg1",
		includeFilters= {
			@Filter(type=FilterType.ANNOTATION,classes= {Controller.class}),//按注解类型指定包含规则
			@Filter(type=FilterType.ASSIGNABLE_TYPE,classes= {BookService.class}),//按照给定的类型指定包含规则
			@Filter(type=FilterType.CUSTOM,classes= {MyTypeFilter.class})
		},
		useDefaultFilters = false)
@ComponentScans({@ComponentScan("com.mashibing.test.case7.scan.pkg2"),@ComponentScan("com.mashibing.test.case7.scan.pkg3")})
@Import({Color.class,Red.class, MyImportSelector.class, MyImportBeanDefinitionRegistrar.class, MyDeferredImportSelector.class})
@ImportResource("classpath:com/mashibing/test/case7/additional/beans.xml")
public class ComplexAnnotationConfig {
	
	@Configuration
	@Order(90)
	class InnerClass{
		@Bean
		public Teacher teacher() {
			return new Teacher("salye");
		}
	}
	
	@Value("${person.name}")
	private String name;

	public String getName() {
		return name;
	}

	@Bean
	public Book book(){
		return new Book("spring",50);
	}
	
    @Bean(name = "bill")
    public Person person1(){
        return new Person("Bill Gates",62);
    }
    
    @Conditional({LinuxCondition.class})
    @Bean("linus")
    public Person person2(){
        return new Person("Linus",48);
    }
}
